home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
181_01
/
where.c
< prev
next >
Wrap
Text File
|
1985-12-11
|
39KB
|
776 lines
/****************************************************************************
* WHERE *
* *
* WHERE is a program to locate files on a disk. It requires DOS 2.x or *
* above. It will search through all subdirectories of the disk looking *
* for files which match information coming from the command line. *
* *
* The command line syntax is: *
* *
* WHERE [ starting directory ] filename.ext [p] (for file prompting) *
* *
* Rule: if a directory name is the last item in the path name, then *
* the directory name MUST be followed by a backslash or else it *
* will be considered a filespec. *
* *
* This program originally came from the Oct. 85 issue of PC Tech Journal. *
* While it was written originally for the Mark Williams compiler, this *
* version is for the Microsoft C compiler, vsn 3.0 or later. *
* *
* George Defenbaugh, 918-622-7926, 10034 E. 29th St. Tulsa, OK 74129 *
****************************************************************************/
/****************************************************************************
* C header files *
* These identify library routines. LINT_ARGS must be defined first. *
****************************************************************************/
#define LINT_ARGS = 1 /* value doesn't matter, only definition does */
#include <conio.h> /* for console i/o */
#include <dos.h> /* for DOS interrupt calls */
#include <stdio.h> /* for standard i/o */
#include <string.h> /* for string functions */
union REGS inregs,outregs; /* register structure for DOS calls */
/****************************************************************************
* Structure for MS-DOS date and time fields returned by DOS functions *
* See DOS Tech Reference for more information *
****************************************************************************/
struct msdos_date
{
unsigned ms_sec : 5; /* time in 2 sec. int (5 bits) */
unsigned ms_min : 6; /* minutes (6 bits) */
unsigned ms_hour : 5; /* hours (5 bits) */
unsigned ms_day : 5; /* day of the month (5 bits) */
unsigned ms_month : 4; /* month (4 bits) */
unsigned ms_year : 7; /* year since 1980 (7 bits) */
};
/****************************************************************************
* Define the DOS Disk Transfer Area (DTA). The structure will be filled *
* in by DOS for interrupt 21H calls. See DOS Tech Ref for more info *
****************************************************************************/
struct DTA
{
char DTA_dosinfo[21]; /* reserved for DOS use */
char DTA_attr; /* file attribute byte */
struct msdos_date DTA_date; /* date structure from above */
long DTA_size; /* file size */
char DTA_filename[13]; /* file name (w/o path) */
};
/****************************************************************************
* Macros *
****************************************************************************/
/* This macro returns the number of elements of its array argument */
#define SIZE(x) (sizeof(x)/sizeof(x[0]))
/****************************************************************************
* Definition of constants *
****************************************************************************/
#define not ! /* C normally uses the ! for NOT */
#define and & /* C normally uses the & for AND */
#define lower_half_reg 0x00ff /* mask for anding into lower register half */
#define carry_set 0x0001 /* mask for flag register carry bit */
#define no_type 0x06 /* gets system and hidden files too */
#define directory_type 0x16 /* directory bit on, with system and hidden */
#define directory_only 0x10 /* directory bit only is on */
#define no_more_files 18 /* DOS return code for no more files */
#define full_screen 23 /* max number of lines on a screen */
#define end_of_string '\0' /* C uses a binary zero for end of string */
#define backslash '\\' /* The backslash character */
#define colon '\:' /* The colon character */
#define stop 'n' /* Used with the continue_pgm switch */
#define no 'n' /* Used with the user_want_prompt switch */
#define continue 'y' /* Used with the continue_pgm switch */
#define yes 'y' /* Used with the user_want_prompt switch */
#define a_ronly 0x01 /* Read only file */
#define a_hidden 0x02 /* Hidden file */
#define a_system 0x04 /* System file */
#define a_directory 0x10 /* Directory */
#define a_archive 0x20 /* Archive bit */
#define n_directory 'd' /* switch value if directories are prompted */
#define n_ronly 'r' /* Read only file */
#define n_write 'w' /* Write allowed */
#define n_hidden 'h' /* Hidden file */
#define n_visible 'v' /* Visible file */
#define n_system 's' /* System file */
#define n_user 'u' /* User file */
#define n_archive 'a' /* Archive bit */
#define n_not_archive 'n' /* Not archived */
/****************************************************************************
* The next structure and array are for analyzing the attribute bits for *
* each file. The structure consists of pairs of integers, the first *
* integer in each pair is a bit mask which has the bit set that *
* corresponds to a particular attribute for a file. The second integer *
* is a character that is displayed if the attribute byte has the bit *
* set that matches the mask. The attribute bits are: *
* *
* a - archive bit *
* d - directory *
* h - hidden file *
* r - read only file *
* s - system file *
****************************************************************************/
static struct atr { /* Attribute structure */
char a_mask;